SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Emilio Augusto Veras Ivanovich
-- Create date: 12/01/2011
-- Description:	Insert data to Call's Table
-- =============================================
ALTER PROCEDURE [dbo].[PROCEDURE_CALLS]
	-- Add the parameters for the stored procedure here
	@ID BIGINT = 0,
	@COMMENTS VARCHAR(255) = NULL,
	@OPEN_BY_USER VARCHAR(60),
	@SAMPLE BIT = 0,
	@SHIPPING BIT = 0,
	@RESULT BIT = 0,
	@VIALS BIT = 0,
	@PROMOTIONAL BIT = 0,
	@PRICES BIT = 0,
	@VISIT BIT = 0,
	@DOCTOR_ID VARCHAR(12),
	@CLOSE_BY_USER VARCHAR(60) = NULL
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;
	--Check whether exists or not the ID to be inserted.
	IF @ID = 0
	BEGIN
		-- Variables
		EXECUTE [dbo].[PROCEDURE_RESEED_CALLS];
		-- Insert statements for procedure here.
		INSERT INTO [SGLL].[dbo].[CALLS] ([COMMENTS],[OPEN_BY_USER],[SAMPLE],[SHIPPING],[RESULT],[VIALS],[PROMOTIONAL],[PRICES],[VISIT],[DOCTOR_ID],[CLOSE_BY_USER]) VALUES (@COMMENTS, @OPEN_BY_USER, @SAMPLE, @SHIPPING, @RESULT, @VIALS, @PROMOTIONAL, @PRICES, @VISIT, @DOCTOR_ID, @CLOSE_BY_USER);
	END;
	ELSE
	BEGIN
		-- Update statements for procedure here.
		UPDATE [SGLL].[dbo].[CALLS] SET [COMMENTS] = @COMMENTS, [CLOSE_BY_USER] = @CLOSE_BY_USER, [UPDATED_DATE] = GETDATE() WHERE [ID] = @ID;
	END;
END